/**
 * 在线客服分组列表js
 * @author linfeng
 * @since 2019/12/24
 */
let layer = layui.layer;

layui.define(['index', 'form', 'table', 'laypage'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var table = layui.table;
    var laypage = layui.laypage;

    form.render();

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        defaultToolbar: [''],
        limit: json.pageSize,
        height: 'full-190'
    });

    laypage.render(zmnPage.laypageOptions(json));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.groupId);
    });

    form.on("switch(chk_one_status)", function (obj) {
        let  url = "/online/service/group/updateStatus.action";
        let groupId = obj.elem.getAttribute("key");
        let status = obj.elem.checked ? 2 : 1;
        switch (status) {
            case 1:
                zmnPage.ajaxSimple(url, {ids: groupId, status: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {ids: groupId, status: 2}, 1000);
                break;
        }
        setTimeout(function () {
            location.reload(true);
        }, 3000);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        //启用停用
        if (obj.event == "start" || obj.event == "stop") {
            if (ids.length === 0) {
                return layer.msg("请至少选择一条数据！", {icon: 2});
            }
            zmnPage.layStartStopBatch(obj, "/online/service/group/updateStatus.action", ids.join(","));
        }
    });

    //查询条件重置
    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-online-service-group-filter", {
            "keyWord": ""
        });
        return false;
    });

    //对外暴露的接口
    exports('online_service_group_list_js', {});
});

//显示描述
function show_tips(flag, tips, obj){
    //小tips
    //如果没有权限则提示
    if (!flag) {
        layer.tips(tips,obj,{
            tips:[1,'#3595CC'],
            time:3000
        })
    }
}

